package com.yunda.crypt.security.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by Eenie on 2017/8/24.
 * Email: eeniework@gmail.com
 * Des:
 */

public class QueryStrUtil {
    public QueryStrUtil() {
    }

    public static String map2QueryStr(Map<String, Object> var0) {
        String var4;
        if(var0 != null && !var0.isEmpty()) {
            Iterator var1 = var0.keySet().iterator();

            String var2;
            String var3;
            for(var2 = ""; var1.hasNext(); var2 = var2 + var3 + "=" + var0.get(var3) + "&") {
                var3 = (String)var1.next();
            }

            var4 = var2;
            if(var2.length() > 1) {
                var4 = var2;
                if("&".equals(var2.substring(var2.length() - 1))) {
                    var4 = var2.substring(0, var2.length() - 1);
                }
            }
        } else {
            var4 = null;
        }

        return var4;
    }

    public static Map<String, String> queryStr2Map(String var0) {
        HashMap var6;
        if(var0 != null && !var0.isEmpty()) {
            String[] var1 = var0.split("&");
            HashMap var2 = new HashMap();
            int var3 = var1.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                String[] var5 = var1[var4].split("=");
                String var7;
                switch(var5.length) {
                    case 1:
                        var0 = var5[0];
                        var7 = "";
                        break;
                    default:
                        var0 = var5[0];
                        var7 = var5[1];
                }

                var2.put(var0, var7);
            }

            var6 = var2;
        } else {
            var6 = null;
        }

        return var6;
    }

    public static Map<String, String> splitUrlQuery(String var0) {
        HashMap var1 = new HashMap();
        String[] var5 = var0.split("&");
        if(var5 != null && var5.length > 0) {
            int var2 = var5.length;

            for(int var3 = 0; var3 < var2; ++var3) {
                String[] var4 = var5[var3].split("=", 2);
                if(var4 != null && var4.length == 2) {
                    var1.put(var4[0], var4[1]);
                }
            }
        }

        return var1;
    }
}
